﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:ADU_CONSUMHIS
	/// </summary>
	public partial class ADU_CONSUMHIS : BaseDAL<GSLMS.Entity.TB_ADU_CONSUMHIS>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public ADU_CONSUMHIS()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_ADU_CONSUMHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ARRID", model.ARRID),
								new OracleParameter("P_SUMOPINION", model.SUMOPINION),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SUMBY", model.SUMBY),
								new OracleParameter("P_SUMDATE", model.SUMDATE),
								new OracleParameter("P_ADURESULT", model.ADURESULT),
								new OracleParameter("P_TOUSER", model.TOUSER)};
  
			for (int i = 0; i < 9; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_consumhis_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_ADU_CONSUMHIS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ARRID", model.ARRID),
								new OracleParameter("P_SUMOPINION", model.SUMOPINION),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SUMBY", model.SUMBY),
								new OracleParameter("P_SUMDATE", model.SUMDATE),
								new OracleParameter("P_ADURESULT", model.ADURESULT),
								new OracleParameter("P_TOUSER", model.TOUSER)};
  
			for (int i = 0; i < 9; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_consumhis_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_consumhis_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_ADU_CONSUMHIS DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_ADU_CONSUMHIS model = new GSLMS.Entity.TB_ADU_CONSUMHIS();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["ARRID"]!=null && dr["ARRID"].ToString()!="")
				{
					model.ARRID=OracleHelper.ToLong(dr["ARRID"].ToString());
				}
				if(dr["SUMOPINION"]!=null && dr["SUMOPINION"].ToString()!="")
				{
					model.SUMOPINION=dr["SUMOPINION"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["SUMBY"]!=null && dr["SUMBY"].ToString()!="")
				{
					model.SUMBY=dr["SUMBY"].ToString();
				}
				if(dr["SUMDATE"]!=null && dr["SUMDATE"].ToString()!="")
				{
					model.SUMDATE=DateTime.Parse(dr["SUMDATE"].ToString());
				}
				if(dr["ADURESULT"]!=null && dr["ADURESULT"].ToString()!="")
				{
                    model.ADURESULT = OracleHelper.ToInt(dr["ADURESULT"].ToString());
				}
				if(dr["TOUSER"]!=null && dr["TOUSER"].ToString()!="")
				{
					model.TOUSER=dr["TOUSER"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_ADU_CONSUMHIS GetByID(long ID)
		{
			GSLMS.Entity.TB_ADU_CONSUMHIS sModel = new GSLMS.Entity.TB_ADU_CONSUMHIS();
			string sql = "";
			sql = "select * from TB_ADU_CONSUMHIS where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_ADU_CONSUMHIS> GetList(GSLMS.Entity.TB_ADU_CONSUMHIS searchParam)
		{
			var list=new List<GSLMS.Entity.TB_ADU_CONSUMHIS>();
			DataTable dt = null;
			string tblName = "TB_ADU_CONSUMHIS";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_ADU_CONSUMHIS model = new GSLMS.Entity.TB_ADU_CONSUMHIS();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

